package co.edu.unal.bioingenium.kbmed.retrieval.weighting;

import co.edu.unal.bioingenium.kbmed.util.math.UtilMath;

/**
 *
 * @author Alejandro Riveros Cruz
 */
public class TFIDF {

    /**
     * 
     * @param wordFrequency
     * @param totalWordsInDocument
     * @param totalDocuments
     * @param totalDocumentsWithWord
     * @return
     */
    public static float getTFIDF(int wordFrequency, int totalWordsInDocument, int totalDocuments, int totalDocumentsWithWord) {
        return ((float) wordFrequency / (float) totalWordsInDocument) * getIDF(totalDocuments, totalDocumentsWithWord);
    }

    /**
     * 
     * @param totalDocuments
     * @param totalDocumentsWithWord
     * @return
     */
    public static float getIDF(int totalDocuments, int totalDocumentsWithWord) {
        return UtilMath.log2((float) (totalDocuments) / (float) (totalDocumentsWithWord));
    }
}
